﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace IGGWindowApp.Panels
{
    public partial class PanelTitleLeft : UserControl
    {
        public delegate void ItemSelectedHandler(string item);
        public event ItemSelectedHandler ItemSelected;

        public PanelTitleLeft()
        {
            InitializeComponent();
        }

        public void UpdateItem(string item, int index)
        {
            this.Controls[index].Controls[0].Text = item;
            Size szee = TextRenderer.MeasureText(item, new System.Drawing.Font("Franklin Gothic Book", 12F, FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
            this.Controls[index].Size = szee;
            this.Controls[index].Controls[0].Refresh();
        }

        public void Initialize(string[] items)
        {
            FontStyle currentStyle = FontStyle.Bold;
            Cursor currentCursor = System.Windows.Forms.Cursors.Default;
            Color currentColor = System.Drawing.SystemColors.Control;
            int index = items.Length - 1;
            Panel[] panels = new Panel[items.Length];
            foreach (string item in items)
            {
                Size szee = TextRenderer.MeasureText(item, new System.Drawing.Font("Franklin Gothic Book", 12F, currentStyle, System.Drawing.GraphicsUnit.Point, ((byte)(0))));

                Label label = new Label();
                label.BackColor = System.Drawing.SystemColors.ControlDarkDark;
                label.Dock = System.Windows.Forms.DockStyle.Fill;
                label.Font = new System.Drawing.Font("Franklin Gothic Book", 12F, currentStyle, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                label.ForeColor = currentColor;
                label.Location = new System.Drawing.Point(0, 0);
                label.Click += new EventHandler(label_Click);

                label.Cursor = currentCursor;
                label.Size = new System.Drawing.Size(64, 23);
                label.Text = item;
                label.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

                panels[index] = new Panel();
                panels[index].Controls.Add(label);
                panels[index].Dock = System.Windows.Forms.DockStyle.Left;
                panels[index].Location = new System.Drawing.Point(0, 0);
                panels[index].Size = new System.Drawing.Size(szee.Width + 5, 24);

                currentStyle = FontStyle.Regular;
                currentCursor = System.Windows.Forms.Cursors.Hand;
                currentColor = System.Drawing.Color.DarkGray;
                index--;
            }
            this.Controls.AddRange(panels);
        }

        private void label_Click(object sender, EventArgs e)
        {
            Label labl = sender as Label;
            ItemSelected(labl.Text);
        }


    }
}
